package com.ve.bluetooth;
import android.bluetooth.*;
import android.util.*;
import java.lang.reflect.*;

public class ClsUtils {  

    static public boolean createBond(Class<?> btClass, BluetoothDevice btDevice)  throws Exception {  
        Method createBondMethod = btClass.getMethod("createBond");  
        Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);  
        return returnValue.booleanValue();  
    }  


    static public boolean removeBond(Class<?> btClass, BluetoothDevice btDevice)  throws Exception {  
        Method removeBondMethod = btClass.getMethod("removeBond");  
        Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice);  
        return returnValue.booleanValue();  
    }  

    static public boolean setPin(Class<? extends BluetoothDevice> btClass, BluetoothDevice btDevice,  String str) throws Exception {  
        try {  
            Method removeBondMethod = btClass.getDeclaredMethod("setPin",  new Class[]{byte[].class});  
            Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice,new Object[]{str.getBytes()});  
            Log.e("returnValue", "" + returnValue);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return true;
    }  
    static public boolean cancelPairingUserInput(Class<?> btClass, BluetoothDevice device)  throws Exception {  
        Method createBondMethod = btClass.getMethod("cancelPairingUserInput");  
        Boolean returnValue = (Boolean) createBondMethod.invoke(device);  
        return returnValue.booleanValue();  
    }  
    static public boolean cancelBondProcess(Class<?> btClass, BluetoothDevice device)throws Exception {  
        Method createBondMethod = btClass.getMethod("cancelBondProcess");  
        Boolean returnValue = (Boolean) createBondMethod.invoke(device);  
        return returnValue.booleanValue();  
    } 

    static public void setPairingConfirmation(Class<?> btClass, BluetoothDevice device, boolean isConfirm)throws Exception {
    	Method setPairingConfirmation = btClass.getDeclaredMethod("setPairingConfirmation", boolean.class); 
    	setPairingConfirmation.invoke(device, isConfirm);
    }

    static public void printAllInform(Class clsShow) {  
        try {  
            Method[] hideMethod = clsShow.getMethods();  
            int i = 0;  
            for (; i < hideMethod.length; i++) {  
                Log.i(clsShow.toString(),"method["+i+"]=="+hideMethod[i].getName());  
            }
            Field[] allFields = clsShow.getFields();  
            for (i = 0; i < allFields.length; i++) {  
                Log.i(clsShow.toString(),"Field name=="+ allFields[i].getName());  
            }
        } catch (Exception e) { 
            e.printStackTrace();  
        }  
    }  
}
